<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
  function Person() {}
  let p1 = new Person();
  p1.name = "王冰冰";
  p1.age = 23;
  p1.run = function () {
    console.log(this.name + "," + this.age);
  }
  p1.run();

  function Car() {
    this.name = "Ferrari";
    this.price = 200;
    this.run = function () {
      console.log(this.name + "," + this.price);
    }
  }
  let c1 = new Car();
  c1.run();

  let p2 = {};
  p2.name = "张扬";
  p2.age = 24;
  p2.run = function () {
    console.log(this.name + "," + this.age);
  }
  p2.run();

  // 将商品信息封装到一个对象中, 在数组里面装多个表示商品信息的对象
  let arr = [{title:"小米手机", price:5000, num:500},
      {title:"华为电视", price:3000, num:100},
      {title:"vivo手机", price:4000, num:200},
      {title:"一加手机", price:2000, num:300}]
  //得到table对象
  let table = document.querySelector("table");
  //遍历数组
  for (let item of arr) {
      let tr = document.createElement("tr");
      let titleTd = document.createElement("td");
      let priceTd = document.createElement("td");
      let numTd = document.createElement("td");
      //给td添加显示的商品信息
      titleTd.innerText = item.title;
      priceTd.innerText = item.price;
      numTd.innerText = item.num;
      tr.append(titleTd,priceTd,numTd);
      //把tr装进table
      table.append(tr);
  }


</script>
</body>
</html>